package com.passwordvalidator;

public class PasswordValidator {

    public static boolean validate(String password) {
        return isLongEnough(password)
                && containsAtLeaseOneUnderscore(password)
                && containsAtLeaseOneLowercase(password)
                && containsAtLeaseOneUppercase(password)
                && containsAtLeaseOneNumber(password);
    }

    private static boolean containsAtLeaseOneUnderscore(String password) {
        return password.contains("_");
    }

    private static boolean containsAtLeaseOneUppercase(String password) {
        return password.matches(".*[A-Z]+.*");
    }

    private static boolean containsAtLeaseOneLowercase(String password) {
        return password.matches(".*[a-z]+.*");
    }

    private static boolean containsAtLeaseOneNumber(String password) {
        return password.matches(".*\\d+.*");
    }

    private static boolean isLongEnough(String password) {
        return password.length() > 8;
    }
}
